﻿using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Dm;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.SettingManagement;
using Volo.Abp.SettingManagement.EntityFrameworkCore;

namespace AcmeDameng.EntityFrameworkCore
{
    public class FixedEfCoreSettingRepository : EfCoreSettingRepository, ITransientDependency
    {
        public FixedEfCoreSettingRepository(IDbContextProvider<ISettingManagementDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }


        public override Task<Setting> FindAsync(string name, string providerName, string providerKey, CancellationToken cancellationToken = default)
        {
            return base.FindAsync(name, providerName, providerKey, cancellationToken);
        }

        public override async Task<List<Setting>> GetListAsync(string providerName, string providerKey, CancellationToken cancellationToken = default)
        {
            var dbContext = await GetDbContextAsync();

            var results = await dbContext.Settings.Where(x => x.ProviderName == providerName && x.ProviderKey == providerKey).ToListAsync();
            return results;
        }

        public override Task<List<Setting>> GetListAsync(string[] names, string providerName, string providerKey, CancellationToken cancellationToken = default)
        {
            return base.GetListAsync(names, providerName, providerKey, cancellationToken);
        }

    }
}
